//-
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

include /app/helpers/jade/mixins
include /app/configuration/mixins

-var form = 'persistenceConfiguration'
-var model = '$ctrl.clonedCluster.persistenceStoreConfiguration'
-var enabled = model + '.enabled'

panel-collapsible(
    ng-form=form
    on-open=`ui.loadPanel('${form}')`
    ng-show='$ctrl.available(["2.1.0", "2.3.0"])'
)
    panel-title Persistence store
    panel-description
        | Configures Apache Ignite Native Persistence.
        a.link-success(href='https://apacheignite.readme.io/docs/distributed-persistent-store' target='_blank') More info
    panel-content.pca-form-row(ng-if=`$ctrl.available(["2.1.0", "2.3.0"]) && ui.isPanelLoaded('${form}')`)
        .pca-form-column-6.pc-form-grid-row
            .pc-form-grid-col-60
                +form-field__checkbox({
                    label: 'Enabled',
                    model: enabled,
                    name: '"PersistenceEnabled"',
                    tip: 'Flag indicating whether to configure persistent configuration'
                })
            .pc-form-grid-col-60
                +form-field__text({
                    label: 'Store path:',
                    model: `${model}.persistentStorePath`,
                    name: '"PersistenceStorePath"',
                    disabled: `!(${enabled})`,
                    placeholder: 'Input store path',
                    tip: 'A path the root directory where the Persistent Store will persist data and indexes'
                })
            .pc-form-grid-col-60
                +form-field__checkbox({
                    label: 'Metrics enabled',
                    model: `${model}.metricsEnabled`,
                    name: '"PersistenceMetricsEnabled"',
                    disabled: `!${enabled}`,
                    tip: 'Flag indicating whether persistence metrics collection is enabled'
                })
            .pc-form-grid-col-60
                +form-field__checkbox({
                    label: 'Always write full pages',
                    model: `${model}.alwaysWriteFullPages`,
                    name: '"PersistenceAlwaysWriteFullPages"',
                    disabled: `!${enabled}`,
                    tip: 'Flag indicating whether always write full pages'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Checkpointing frequency:',
                    model: `${model}.checkpointingFrequency`,
                    name: '"PersistenceCheckpointingFrequency"',
                    disabled: `!(${enabled})`,
                    placeholder: '180000',
                    min: '1',
                    tip: 'Frequency which is a minimal interval when the dirty pages will be written to the Persistent Store'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Checkpointing page buffer size:',
                    model: `${model}.checkpointingPageBufferSize`,
                    name: '"PersistenceCheckpointingPageBufferSize"',
                    disabled: `!(${enabled})`,
                    placeholder: '268435456',
                    min: '0',
                    tip: 'Amount of memory allocated for a checkpointing temporary buffer'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'Checkpointing threads:',
                    model: `${model}.checkpointingThreads`,
                    name: '"PersistenceCheckpointingThreads"',
                    disabled: `!(${enabled})`,
                    placeholder: '1',
                    min: '1',
                    tip: 'A number of threads to use for the checkpointing purposes'
                })
            .pc-form-grid-col-60
                +form-field__dropdown({
                    label: 'WAL mode:',
                    model: `${model}.walMode`,
                    name: '"PersistenceWalMode"',
                    disabled: `!(${enabled})`,
                    placeholder: 'DEFAULT',
                    options: '[\
                        {value: "DEFAULT", label: "DEFAULT"},\
                        {value: "LOG_ONLY", label: "LOG_ONLY"},\
                        {value: "BACKGROUND", label: "BACKGROUND"},\
                        {value: "NONE", label: "NONE"}\
                    ]',
                    tip: 'Type define behavior wal fsync.\
                        <ul>\
                            <li>DEFAULT - full-sync disk writes</li>\
                            <li>LOG_ONLY - flushes application buffers</li>\
                            <li>BACKGROUND - does not force application&#39;s buffer flush</li>\
                            <li>NONE - WAL is disabled</li>\
                        </ul>'
                })
            .pc-form-grid-col-60
                +form-field__text({
                    label: 'WAL store path:',
                    model: `${model}.walStorePath`,
                    name: '"PersistenceWalStorePath"',
                    disabled: `!(${enabled})`,
                    placeholder: 'Input store path',
                    tip: 'A path to the directory where WAL is stored'
                })
            .pc-form-grid-col-60
                +form-field__text({
                    label: 'WAL archive path:',
                    model: `${model}.walArchivePath`,
                    name: '"PersistenceWalArchivePath"',
                    disabled: `!(${enabled})`,
                    placeholder: 'Input archive path',
                    tip: 'A path to the WAL archive directory'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL segments:',
                    model: `${model}.walSegments`,
                    name: '"PersistenceWalSegments"',
                    disabled: `!(${enabled})`,
                    placeholder: '10',
                    min: '1',
                    tip: 'A number of WAL segments to work with'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL segment size:',
                    model: `${model}.walSegmentSize`,
                    name: '"PersistenceWalSegmentSize"',
                    disabled: `!(${enabled})`,
                    placeholder: '67108864',
                    min: '0',
                    tip: 'Size of a WAL segment'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL history size:',
                    model: `${model}.walHistorySize`,
                    name: '"PersistenceWalHistorySize"',
                    disabled: `!(${enabled})`,
                    placeholder: '20',
                    min: '1',
                    tip: 'A total number of checkpoints to keep in the WAL history'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL flush frequency:',
                    model: `${model}.walFlushFrequency`,
                    name: '"PersistenceWalFlushFrequency"',
                    disabled: `!(${enabled})`,
                    placeholder: '2000',
                    min: '1',
                    tip:'How often will be fsync, in milliseconds. In background mode, exist thread which do fsync by timeout'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL fsync delay:',
                    model: `${model}.walFsyncDelayNanos`,
                    name: '"PersistenceWalFsyncDelay"',
                    disabled: `!(${enabled})`,
                    placeholder: '1000',
                    min: '1',
                    tip: 'WAL fsync delay, in nanoseconds'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'WAL record iterator buffer size:',
                    model: `${model}.walRecordIteratorBufferSize`,
                    name: '"PersistenceWalRecordIteratorBufferSize"',
                    disabled: `!(${enabled})`,
                    placeholder: '67108864',
                    min: '1',
                    tip: 'How many bytes iterator read from disk(for one reading), during go ahead WAL'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Lock wait time:',
                    model: `${model}.lockWaitTime`,
                    name: '"PersistenceLockWaitTime"',
                    disabled: `!(${enabled})`,
                    placeholder: '10000',
                    min: '1',
                    tip: 'Time out in second, while wait and try get file lock for start persist manager'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Rate time interval:' ,
                    model: `${model}.rateTimeInterval`,
                    name: '"PersistenceRateTimeInterval"',
                    disabled: `!(${enabled})`,
                    placeholder: '60000',
                    min: '1000',
                    tip: 'The length of the time interval for rate - based metrics. This interval defines a window over which hits will be tracked.'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Thread local buffer size:',
                    model: `${model}.tlbSize`,
                    name: '"PersistenceTlbSize"',
                    disabled: `!(${enabled})`,
                    placeholder: '131072',
                    min: '1',
                    tip: 'Define size thread local buffer. Each thread which write to WAL have thread local buffer for serialize recode before write in WAL'
                })
            .pc-form-grid-col-30
                +form-field__number({
                    label: 'Sub intervals:',
                    model: `${model}.subIntervals`,
                    name: '"PersistenceSubIntervals"',
                    disabled: `!(${enabled})`,
                    placeholder: '5',
                    min: '1',
                    tip: 'Number of sub - intervals the whole rate time interval will be split into to calculate rate - based metrics'
                })
            .pc-form-grid-col-60
                +form-field__number({
                    label: 'WAL auto archive after inactivity:',
                    model: `${model}.walAutoArchiveAfterInactivity`,
                    name: '"PersistenceWalAutoArchiveAfterInactivity"',
                    disabled: `!(${enabled})`,
                    placeholder: '-1',
                    min: '-1',
                    tip: 'Time in millis to run auto archiving segment after last record logging'
                })
        .pca-form-column-6
            +preview-xml-java(model, 'clusterPersistence')
